﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ObjectLibrary;

namespace _0912089_0912172
{
    public abstract class FormItem : VisibleGameEntity3D
    {
        protected bool isChosen = false;
        private bool _enable = true;
        protected int _itemType = 0;

        public int ItemType
        {
            get { return _itemType; }
        }

        protected Vector2 _size;
        protected float _defaultLight = 0.95f;

        public float DefaultLight
        {
            get { return _defaultLight; }
            set { _defaultLight = value; }
        }
        public Vector2 Size
        {
            get { return _size; }
            set { _size = value; }
        }
        public bool Enable
        {
            get { return _enable; }
            set { _enable = value; }
        }
        
        public bool IsChosen
        {
            get { return isChosen; }
            set { isChosen = value; }
        }
        
        private float t = 1f;
        float dLight = 0.02f;

        private void updateT()
        {
            if (t > 1)
            {
                dLight = -0.02f;
            }
            else if (t < 0.7)
            {
                dLight = 0.02f;
            }
            t += dLight;
        }
        public override void Update(GameTime gameTime)
        {

            if (isChosen && _enable)
            {
                updateT();
                ((PlanarModel)_model).FilterColor = Vector4.One * t;
            }
            else
                ((PlanarModel)_model).FilterColor = Vector4.One * _defaultLight;

            base.Update(gameTime);
        }


        virtual public bool isClicked(Vector3 contactPoint)
        {
            return (((PlanarModel)_model).isClicked(contactPoint)&& _enable);
        }
    }
}
